﻿namespace Microsoft.AspNetCore.Builder
{
    //注册使用CORS -跨域访问处理
    public static class RegisterUseCORS
    {
        public static void AddUseCors(this WebApplicationBuilder builder,params string[] urls)
        {
            builder.Services.AddCors(opt =>
            {
                opt.AddDefaultPolicy(builder => builder.WithOrigins(urls).AllowAnyMethod().AllowAnyHeader().AllowCredentials());
                //然后需要在Program中使用app.UseCors();
            });
        }
    }
}
